package com.example.demo.controller;

import com.example.demo.entites.RegionStats;
import com.example.demo.entites.ShowEntity;
import com.example.demo.services.CSVServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Date;
import java.util.List;

@Controller
public class CSVController {
    @Autowired
    CSVServices csvServices;

    @GetMapping("/")
    public String getData(Model model)throws Exception {
        List<RegionStats> regionStatsList = csvServices.getRegionStatsList();

        ShowEntity showEntity = ShowEntity.builder()
                .now(new Date())
                .regionStatsList(regionStatsList)
                .globalNum(csvServices.getGlobalNum())
                .build();

        model.addAttribute("data",showEntity);
        return "GetData";
    }
    @GetMapping("/findCountry")
    public String getCountryData(Model model,String country) throws Exception {

        List<RegionStats> countryList = csvServices.fetchCountryConfirmedRecords(country.toUpperCase());
        model.addAttribute("countryList",countryList);
        return "GetCountryData";

    }
}
